<?php

namespace App\Http\Resources\orders;

use App\Models\fund\Coupon;
use App\Models\goods\Goods;
use App\Models\goods\GoodsOrder;
use App\Models\goods\Order;
use Illuminate\Http\Resources\Json\ResourceCollection;

class OrdersPageCollection extends ResourceCollection
{
    /**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'total' => $this->resource->total(),
            'perPage' => $this->resource->perPage(),
            'current_page' => $this->resource->currentPage(),
            'items' => $this->collection->map(function (GoodsOrder $item) {
                $status_text = [
                    0 => '未审核',
                    1 => '审核失败',
                    2 => '审核通过'
                ];
                return [
                    'user_name' => $item->user->name,
                    'score' => $item->integral,
                    'id' => $item->goods->id,
                    'goods_name' => $item->goods->name,
                    'goods_img' => $item->goods->img,
                    'status' => $item->status,
                    'status_text' => $status_text[$item->status],
                    'created_at' => $item->created_at->toDateTimeString(),
                ];
            })
        ];

    }
}
